home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / (A)Z / (A)Z8.ADF / Dazzlers / Dazzle.c < prev    next >
C/C++ Source or Header  |  1987-12-16  |  4KB  |  151 lines

  1. /************************************************************************
  2.  * Dazzlers - Written by Bryan Ford                                     *
  3.  *                                                                      *
  4.  * This is a demonstration of the color graphics capabilities of the    *
  5.  * Amiga - brought to you by a routine I thought of on one of those     *
  6.  * "hacker's nights" - you know, the kind when you never get to bed.    *
  7.  *                                                                      *
  8.  * Press the left putton to quit, right button to pause, right button   *
  9.  * to resume.                                                           *
  10.  *                                                                      *
  11.  * This program was compiled on Lattice C version 3.03.  It             *
  12.  * will probably work on most other C compilers for the Amiga.          *
  13.  *                                                                      *
  14.  * This program is in the public domain.  Use it as you see fit.        *
  15.  ************************************************************************/
  16.  
  17. #include "exec/types.h"
  18. #include "graphics/gfx.h"
  19. #include "graphics/rastport.h"
  20. #include "graphics/gfxbase.h"
  21. #include "intuition/intuition.h"
  22. #include "libraries/dos.h"
  23.  
  24. /* Library bases */
  25. struct IntuitionBase *IntuitionBase; /* = NULL */
  26. struct GfxBase *GfxBase; /* = NULL */
  27.  
  28. /* Screen stuff */
  29. struct Screen *Scr; /* = NULL */
  30. struct Window *Win; /* = NULL */
  31.  
  32. /* Secondary bitmap */
  33. struct BitMap *SecBitMap; /* = NULL */
  34.  
  35. /* Misc */
  36. struct IntuiMessage *IM;
  37. COUNT WideCount = 5;
  38. BOOL NoDazzle; /* = FALSE */
  39. UWORD Code;
  40.  
  41. /* Finish routine */
  42. VOID Finish(RetCode)
  43. {
  44.    /* Free the secondary bitmap */
  45.    if (SecBitMap != NULL)
  46.       FreeBitMap(SecBitMap);
  47.  
  48.    /* Close the screen and window */
  49.    if (Win != NULL)
  50.       CloseWindow(Win);
  51.    if (Scr != NULL)
  52.       CloseScreen(Scr);
  53.  
  54.    /* Close the libraries */
  55.    if (IntuitionBase != NULL)
  56.       CloseLibrary(IntuitionBase);
  57.    if (GfxBase != NULL)
  58.       CloseLibrary(GfxBase);
  59.  
  60.    /* Exit */
  61.    exit(RetCode);
  62. }
  63.  
  64. /* Open the libraries */
  65. VOID OpenLibs()
  66. {
  67.    /* Open the Graphics library */
  68.    if ((GfxBase = (struct GfxBase*)
  69.       OpenLibrary("graphics.library",32)) == NULL)
  70.       Finish(RETURN_FAIL);
  71.  
  72.    /* Open the Intuition library */
  73.    if ((IntuitionBase = (struct IntuitionBase*)
  74.       OpenLibrary("intuition.library",32)) == NULL)
  75.       Finish(RETURN_FAIL);
  76. }
  77.  
  78. struct NewScreen NewScr = {
  79.    0, 0, 320, 200, 5, 0, 0, NULL, CUSTOMSCREEN};
  80.  
  81. struct NewWindow NewWin = {
  82.    0, 0, 320, 200, 0, 0, MOUSEBUTTONS, SIMPLE_REFRESH | BACKDROP |
  83.    BORDERLESS | ACTIVATE | RMBTRAP | NOCAREREFRESH, NULL, NULL, NULL,
  84.    NULL, NULL, 0, 0, 0, 0, CUSTOMSCREEN};
  85.  
  86. VOID OpenScr()
  87. {
  88.    /* Open the screen */
  89.    if ((Scr = (struct Screen*)OpenScreen(&NewScr)) == NULL)
  90.       Finish(RETURN_ERROR);
  91.  
  92.    /* Open the window */
  93.    NewWin.Screen = Scr;
  94.    if ((Win = (struct Window*)OpenWindow(&NewWin)) == NULL)
  95.       Finish(RETURN_ERROR);
  96.  
  97.    /* Get the title bar out of here */
  98.    ShowTitle(Scr,FALSE);
  99.  
  100.    /* Black background */
  101.    SetRGB4(&Scr->ViewPort,0,0,0,0);
  102. }
  103.  
  104. VOID OpenBM()
  105. {
  106.    /* Create the secondary Bitmap */
  107.    if ((SecBitMap = (struct BitMap*)
  108.       AllocBitMap(322,202,5,TRUE)) == NULL)
  109.       Finish(RETURN_ERROR);
  110. }
  111.  
  112. VOID main()
  113. {
  114.    /* Setup */
  115.    OpenLibs();
  116.    OpenScr();
  117.    OpenBM();
  118.  
  119.    FOREVER {
  120.  
  121.       if (NoDazzle == FALSE) {
  122.  
  123.          /* Plant some junk */
  124.          SetAPen(Win->RPort,RangeRand(32));
  125.          WritePixel(Win->RPort,RangeRand(320),RangeRand(200));
  126.  
  127.          /* Abracadabra - figure this out yourself! */
  128.          BltRastPortBitMap(Win->RPort,0,0,SecBitMap,1,0,320,200,0x0c0);
  129.          BltRastPortBitMap(Win->RPort,0,0,SecBitMap,1,2,320,200,0x0e0);
  130.          BltRastPortBitMap(Win->RPort,0,0,SecBitMap,0,1,320,200,0x0e0);
  131.          BltRastPortBitMap(Win->RPort,0,0,SecBitMap,2,1,320,200,0x0e0);
  132.          BltRastPortBitMap(Win->RPort,0,0,SecBitMap,1,1,320,200,
  133.             --WideCount ? 0x0e0 : 0x020);
  134.          BltBitMapRastPort(SecBitMap,1,1,Win->RPort,0,0,320,200,0x0c0);
  135.          if (WideCount == 0)
  136.             WideCount = RangeRand(7) + 1;
  137.       }
  138.   
  139.       /* Check for IntuiMessages */
  140.       if ((IM = (struct IntuiMessage*)GetMsg(Win->UserPort)) != NULL) {
  141.          Code = IM->Code;
  142.          ReplyMsg(IM);
  143.          if (Code == SELECTDOWN)
  144.             Finish(RETURN_OK);
  145.          if (Code == MENUDOWN)
  146.             NoDazzle ^= 1;
  147.       }
  148.    }
  149. }
  150.  
  151.